package ihm;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.SpringLayout;
import javax.swing.border.TitledBorder;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Color;
import java.awt.Window;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTable;

import data.Authentification;
import data.Chat;
import data.Chrono;
import data.Indice;
import data.ListeAlertes;
import data.ListeIndices;
import data.ModeleChat;
import data.ModeleAuthentification;
import data.ModeleChrono;
import data.ModeleConnexion;
import data.ModeleListeAlertes;
import data.ModeleListeIndices;
import data.Temps;
import data.Utilisateur;

import network.Connexion;
import network.Protocol;
import network.SocketUtilisateur;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JTabbedPane;

public class FenetrePrincipale extends JFrame {

	private JPanel contentPane;
	private JTextField txtEnvoyerChat;
	static Connexion con;
	private static Protocol p;
	private static Chat chat;
	private static Authentification auth;
	private static Chrono chronopartie;
	private static ListeAlertes listeAlerte;
	private static ListeIndices listeIndice;
	ModeleListeIndices mli;
	
	/** Alertes **/
	ModeleListeAlertes mla;
    private JTable tableau_alertes; 
    private JTable tableau_indices;
	
	
	static JFrame AttenteConnexion;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {

		/** Ici on creer les class conteneur */
		chat = new Chat();
		auth = new Authentification();
		chronopartie = new Chrono(new Temps(0, 0, 0));;
		listeAlerte = new ListeAlertes();
		listeIndice = new ListeIndices();

		AttenteConnexion = new JFrame("Attente connexion");
		AttenteConnexion.getContentPane().add(new JLabel(
				"\nAttente de connexion de l'Admin ...\n"));
		AttenteConnexion.setMinimumSize(new Dimension(400, 200));
		AttenteConnexion.setAlwaysOnTop(true);
		AttenteConnexion.setLocationRelativeTo(null);
		AttenteConnexion.pack();
		AttenteConnexion.setVisible(true);

		/** On init le protocol avec les class conteneur */
		p = new Protocol(auth, chat, chronopartie, listeIndice, listeAlerte);

		
		/** On lance la socket server */

		con = new Connexion(p);
		con.connect(7000);

		AttenteConnexion.setVisible(false);
		// AttenteConnexion.dispose();

		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					FenetrePrincipale frame = new FenetrePrincipale();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});

	}

	/**
	 * Create the frame.
	 */
	public FenetrePrincipale() {
		setTitle("Murder Party - Joueur");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1000, 650);

		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu mnAction = new JMenu("Action");
		menuBar.add(mnAction);

		JMenuItem mntmConnexion = new JMenuItem("S'authentifier");
		mntmConnexion.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(con.getState()){
					FenetreAuthentifier fenAuthentifier = new FenetreAuthentifier(con,auth);
					fenAuthentifier.setVisible(true);
				}
			}
		});

		mnAction.add(mntmConnexion);

		JMenuItem mntmFermerLaSession = new JMenuItem("Fermer sa session");
		mntmFermerLaSession.setEnabled(true);
		mnAction.add(mntmFermerLaSession);
		mntmFermerLaSession.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//auth.close();
				con.send(new Utilisateur());
			}
		});

		JMenuItem mntmDbloquerUnIndice = new JMenuItem(
				"D\u00E9bloquer un indice");
		mntmDbloquerUnIndice.setEnabled(false);
		mnAction.add(mntmDbloquerUnIndice);

		JMenuItem mntmEchangerUnIndice = new JMenuItem("Echanger un indice");
		mntmEchangerUnIndice.setEnabled(false);
		mnAction.add(mntmEchangerUnIndice);

		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		SpringLayout sl_contentPane = new SpringLayout();
		contentPane.setLayout(sl_contentPane);

		JPanel pnlInfosChronos = new JPanel();
		sl_contentPane.putConstraint(SpringLayout.NORTH, pnlInfosChronos, 0,
				SpringLayout.NORTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.WEST, pnlInfosChronos, 0,
				SpringLayout.WEST, contentPane);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, pnlInfosChronos, 150,
				SpringLayout.NORTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.EAST, pnlInfosChronos, 0,
				SpringLayout.EAST, contentPane);
		contentPane.add(pnlInfosChronos);
		
		JPanel pnlListeIndices = new JPanel();
		sl_contentPane.putConstraint(SpringLayout.NORTH, pnlListeIndices, 0,
				SpringLayout.SOUTH, pnlInfosChronos);
		
		JPanel pnlChat = new JPanel();
		sl_contentPane.putConstraint(SpringLayout.NORTH, pnlChat, 0,
				SpringLayout.SOUTH, pnlInfosChronos);
		
		SpringLayout sl_pnlInfosChronos = new SpringLayout();
		pnlInfosChronos.setLayout(sl_pnlInfosChronos);

		JPanel pnlChronoJoueur = new JPanel();
		sl_pnlInfosChronos.putConstraint(SpringLayout.NORTH, pnlChronoJoueur,
				0, SpringLayout.NORTH, pnlInfosChronos);
		sl_pnlInfosChronos.putConstraint(SpringLayout.WEST, pnlChronoJoueur,
				150, SpringLayout.WEST, pnlInfosChronos);
		sl_pnlInfosChronos.putConstraint(SpringLayout.SOUTH, pnlChronoJoueur,
				0, SpringLayout.SOUTH, pnlInfosChronos);
		sl_pnlInfosChronos.putConstraint(SpringLayout.EAST, pnlChronoJoueur,
				-465, SpringLayout.EAST, pnlInfosChronos);
		pnlChronoJoueur.setBorder(new TitledBorder(null,
				"Temps restant au joueur", TitledBorder.LEADING,
				TitledBorder.TOP, null, null));
		pnlInfosChronos.add(pnlChronoJoueur);

		JPanel pnlChronoPartie = new JPanel();
		sl_pnlInfosChronos.putConstraint(SpringLayout.WEST, pnlChronoPartie, 0,
				SpringLayout.EAST, pnlChronoJoueur);
		pnlChronoPartie.setBorder(new TitledBorder(null,
				"Temps restant de la partie", TitledBorder.LEADING,
				TitledBorder.TOP, null, null));
		sl_pnlInfosChronos.putConstraint(SpringLayout.NORTH, pnlChronoPartie,
				0, SpringLayout.NORTH, pnlInfosChronos);
		sl_pnlInfosChronos.putConstraint(SpringLayout.SOUTH, pnlChronoPartie,
				0, SpringLayout.SOUTH, pnlInfosChronos);
		sl_pnlInfosChronos.putConstraint(SpringLayout.EAST, pnlChronoPartie, 0,
				SpringLayout.EAST, pnlInfosChronos);
		pnlInfosChronos.add(pnlChronoPartie);
		SpringLayout sl_pnlChronoPartie = new SpringLayout();
		pnlChronoPartie.setLayout(sl_pnlChronoPartie);

		JLabel lblChronoPartie = new JLabel("00:00");
		lblChronoPartie.setHorizontalAlignment(SwingConstants.CENTER);
		lblChronoPartie
				.setFont(new Font("Microsoft Sans Serif", Font.PLAIN, 65));
		sl_pnlChronoPartie.putConstraint(SpringLayout.NORTH, lblChronoPartie,
				0, SpringLayout.NORTH, pnlChronoPartie);
		sl_pnlChronoPartie.putConstraint(SpringLayout.WEST, lblChronoPartie, 0,
				SpringLayout.WEST, pnlChronoPartie);
		sl_pnlChronoPartie.putConstraint(SpringLayout.SOUTH, lblChronoPartie,
				0, SpringLayout.SOUTH, pnlChronoPartie);
		sl_pnlChronoPartie.putConstraint(SpringLayout.EAST, lblChronoPartie, 0,
				SpringLayout.EAST, pnlChronoPartie);
		pnlChronoPartie.add(lblChronoPartie);

		JLabel lblBienvenue = new JLabel("Bienvenue,");
		sl_pnlInfosChronos.putConstraint(SpringLayout.NORTH, lblBienvenue, 10,
				SpringLayout.NORTH, pnlInfosChronos);
		sl_pnlInfosChronos.putConstraint(SpringLayout.WEST, lblBienvenue, 10,
				SpringLayout.WEST, pnlInfosChronos);
		pnlInfosChronos.add(lblBienvenue);

		JLabel lblPseudonyme = new JLabel(auth.getPseudoUtilisateur());
		sl_pnlInfosChronos.putConstraint(SpringLayout.NORTH, lblPseudonyme, 44,
				SpringLayout.SOUTH, lblBienvenue);
		sl_pnlInfosChronos.putConstraint(SpringLayout.WEST, lblPseudonyme, 50,
				SpringLayout.WEST, pnlInfosChronos);
		sl_pnlInfosChronos.putConstraint(SpringLayout.EAST, lblPseudonyme, 0,
				SpringLayout.WEST, pnlChronoJoueur);
		SpringLayout sl_pnlChronoJoueur = new SpringLayout();
		pnlChronoJoueur.setLayout(sl_pnlChronoJoueur);

		JLabel lblChronoJoueur = new JLabel("00:00");
		lblChronoJoueur.setForeground(new Color(255, 0, 0));
		sl_pnlChronoJoueur.putConstraint(SpringLayout.NORTH, lblChronoJoueur,
				0, SpringLayout.NORTH, pnlChronoJoueur);
		sl_pnlChronoJoueur.putConstraint(SpringLayout.WEST, lblChronoJoueur, 0,
				SpringLayout.WEST, pnlChronoJoueur);
		sl_pnlChronoJoueur.putConstraint(SpringLayout.SOUTH, lblChronoJoueur,
				0, SpringLayout.SOUTH, pnlChronoJoueur);
		sl_pnlChronoJoueur.putConstraint(SpringLayout.EAST, lblChronoJoueur, 0,
				SpringLayout.EAST, pnlChronoJoueur);
		lblChronoJoueur
				.setFont(new Font("Microsoft Sans Serif", Font.PLAIN, 65));
		lblChronoJoueur.setHorizontalAlignment(SwingConstants.CENTER);
		pnlChronoJoueur.add(lblChronoJoueur);
		pnlInfosChronos.add(lblPseudonyme);
		sl_contentPane.putConstraint(SpringLayout.WEST, pnlChat, 0,
				SpringLayout.EAST, pnlListeIndices);

		// SCROLLPANE INDICE ET CHAT
		
		sl_contentPane.putConstraint(SpringLayout.SOUTH, pnlChat, 0,
				SpringLayout.SOUTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.EAST, pnlChat, 0,
				SpringLayout.EAST, contentPane);
		
		pnlChat.setBorder(new TitledBorder(null, "Chat", TitledBorder.LEADING,
				TitledBorder.TOP, null, null));
		
		sl_contentPane.putConstraint(SpringLayout.NORTH, pnlListeIndices, 0,
				SpringLayout.SOUTH, pnlInfosChronos);
		sl_contentPane.putConstraint(SpringLayout.WEST, pnlListeIndices, 0,
				SpringLayout.WEST, contentPane);
		
		pnlListeIndices.setBorder(new TitledBorder(null, "Liste des indices",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		
		// end 
		
		sl_contentPane.putConstraint(SpringLayout.SOUTH, pnlListeIndices, 0,
				SpringLayout.SOUTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.EAST, pnlListeIndices, -465,
				SpringLayout.EAST, contentPane);
		
		contentPane.add(pnlListeIndices);
		

//		txtListeIndices.addMouseListener(new MouseListener() {
//			
//			@Override
//			public void mouseClicked(MouseEvent e) {
//				  Indice i;
//					txtListeIndices.setText("");
//					for(int index=0;index < listeIndice.size(); index++){
//						i = listeIndice.get(index);
//						txtListeIndices.append(i.getIdIndice()+" | "+i.getLabelIndice()+" | "+i.getCheminIndice()+"\n");
//					}
//					txtListeIndices.repaint();
//					txtListeIndices.revalidate();
//				//afficherPopup(e);
//			}
//			@Override
//			public void mouseReleased(MouseEvent arg0) {
//				//int selectedRow = tabIndices.rowAtPoint(arg0.getPoint());
//				//if (selectedRow != -1)
//				//{
//					//tabIndices.changeSelection(selectedRow, -1, false, false);
//					//afficherPopup(arg0);
//				//}
//			
//			}
//			@Override
//			public void mouseEntered(MouseEvent arg0) {
//				// TODO Auto-generated method stub
//				
//			}
//			@Override
//			public void mouseExited(MouseEvent arg0) {
//				// TODO Auto-generated method stub
//				
//			}
//			@Override
//			public void mousePressed(MouseEvent arg0) {
//				Indice i;
//				txtListeIndices.setText("");
//				for(int index=0;index < listeIndice.size(); index++){
//					i = listeIndice.get(index);
//					txtListeIndices.append(i.getIdIndice()+" | "+i.getLabelIndice()+" | "+i.getCheminIndice()+"\n");
//				}
//				txtListeIndices.repaint();
//				txtListeIndices.revalidate();
//				
//			}
//		});

		
		
		JButton btnDemander = new JButton("Demander un indice");
		sl_contentPane.putConstraint(SpringLayout.NORTH, btnDemander, -35, SpringLayout.SOUTH, pnlListeIndices);
		sl_contentPane.putConstraint(SpringLayout.WEST, btnDemander, -185, SpringLayout.EAST, pnlListeIndices);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, btnDemander, -5, SpringLayout.SOUTH, pnlListeIndices);
		sl_contentPane.putConstraint(SpringLayout.EAST, btnDemander, -25, SpringLayout.EAST, pnlListeIndices);
		pnlListeIndices.add(btnDemander);
		btnDemander.setEnabled(true);
		btnDemander.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				DemanderIndice fd = null;
				try {
					fd = new DemanderIndice(con,listeIndice,auth);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
				fd.setVisible(true);
			}
		});
		
		contentPane.add(pnlChat);
		SpringLayout sl_pnlChat = new SpringLayout();
		pnlChat.setLayout(sl_pnlChat);

		JScrollPane sclpnAffichageChat = new JScrollPane();
		sl_pnlChat.putConstraint(SpringLayout.NORTH, sclpnAffichageChat, 20,
				SpringLayout.NORTH, pnlChat);
		sl_pnlChat.putConstraint(SpringLayout.WEST, sclpnAffichageChat, 0,
				SpringLayout.WEST, pnlChat);
		sl_pnlChat.putConstraint(SpringLayout.EAST, sclpnAffichageChat, 0,
				SpringLayout.EAST, pnlChat);
		pnlChat.add(sclpnAffichageChat);
		
		JButton btnVoir = new JButton("Voir");
		btnVoir.setBounds(496, 404, 51, 23);
		btnVoir.setEnabled(true);
		
		
		JButton btnEchanger = new JButton("Echanger");
		btnEchanger.setEnabled(true);
		
		JTextArea txtaAffichageChat = new JTextArea();
		txtaAffichageChat.setEditable(false);
		sclpnAffichageChat.setViewportView(txtaAffichageChat);

		txtEnvoyerChat = new JTextField();
		sl_pnlChat.putConstraint(SpringLayout.SOUTH, sclpnAffichageChat, -10,
				SpringLayout.NORTH, txtEnvoyerChat);
		sl_pnlChat.putConstraint(SpringLayout.WEST, txtEnvoyerChat, 0,
				SpringLayout.WEST, pnlChat);
		sl_pnlChat.putConstraint(SpringLayout.SOUTH, txtEnvoyerChat, 0,
				SpringLayout.SOUTH, pnlChat);
		sl_pnlChat.putConstraint(SpringLayout.EAST, txtEnvoyerChat, 345,
				SpringLayout.WEST, pnlChat);
		pnlChat.add(txtEnvoyerChat);
		txtEnvoyerChat.setColumns(10);

		JButton btnEnvoyerChat = new JButton("Envoyer");
		btnEnvoyerChat.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (con.getState()) {
					con.send(txtEnvoyerChat.getText());
					chat.addLine("[" + auth.getPseudoUtilisateur() + "] "
							+ txtEnvoyerChat.getText());
				} else {
					System.err.println("Chat hors-connexion");
					return;
				}

			}
		});
		sl_pnlChat.putConstraint(SpringLayout.NORTH, btnEnvoyerChat, 6,
				SpringLayout.SOUTH, sclpnAffichageChat);
		sl_pnlChat.putConstraint(SpringLayout.WEST, btnEnvoyerChat, 6,
				SpringLayout.EAST, txtEnvoyerChat);
		sl_pnlChat.putConstraint(SpringLayout.SOUTH, btnEnvoyerChat, 0,
				SpringLayout.SOUTH, pnlChat);
		pnlChat.add(btnEnvoyerChat);

		/** Les Observeurs **/
		ModeleChat mc = new ModeleChat(txtaAffichageChat);
		chat.addObserver(mc);

		ModeleAuthentification mauth = new ModeleAuthentification(
				lblPseudonyme, lblChronoJoueur, listeIndice, chat, con);
		auth.addObserver(mauth);

		ModeleChrono mchrono = new ModeleChrono(lblChronoPartie);
		chronopartie.addObserver(mchrono);

		ModeleConnexion mcon = new ModeleConnexion(AttenteConnexion);
		con.addObserver(mcon);

		final ModeleListeIndices mli = new ModeleListeIndices();
		listeIndice.addObserver(mli);
		
		mla = new ModeleListeAlertes();
		listeAlerte.addObserver(mla); 
		
		
		/************* ALERTES *************/
		/*mla = new ModeleListeAlertes();
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(6, 27, 541, 143);
		
        
        tableau_alertes = new JTable(mla);
		
	    listeAlerte.addObserver(mla); 
	
		mla.update(listeAlerte, null);
        pnlListeIndices.setLayout(null);
		
        JPanel ongAlertes  = new JPanel();
        
        SpringLayout sl_ongAlertes = new SpringLayout();
        ongAlertes.setLayout(sl_ongAlertes);
        
        JScrollPane sclpnAlertes = new JScrollPane(tableau_alertes);
        sl_ongAlertes.putConstraint(SpringLayout.NORTH, sclpnAlertes, 0, SpringLayout.NORTH, ongAlertes);
        sl_ongAlertes.putConstraint(SpringLayout.WEST, sclpnAlertes, 0, SpringLayout.WEST, ongAlertes);
        sl_ongAlertes.putConstraint(SpringLayout.SOUTH, sclpnAlertes, -24, SpringLayout.SOUTH, ongAlertes);
        sl_ongAlertes.putConstraint(SpringLayout.EAST, sclpnAlertes, 0, SpringLayout.EAST, ongAlertes);
        ongAlertes.add(sclpnAlertes);
      
        tabbedPane.addTab("Alertes",ongAlertes);
        
        JButton btnVoir_1 = new JButton("Voir");
        sl_ongAlertes.putConstraint(SpringLayout.WEST, btnVoir_1, 0, SpringLayout.WEST, ongAlertes);
        sl_ongAlertes.putConstraint(SpringLayout.SOUTH, btnVoir_1, 0, SpringLayout.SOUTH, ongAlertes);
        ongAlertes.add(btnVoir_1);
        pnlListeIndices.add(tabbedPane);
        pnlListeIndices.add(btnDemander);
        pnlListeIndices.add(btnVoir);*/
        
        /*Indice*/
        SpringLayout sl_pnlListeIndices = new SpringLayout();
        sl_pnlListeIndices.putConstraint(SpringLayout.WEST, btnDemander, -185, SpringLayout.EAST, pnlListeIndices);
        sl_pnlListeIndices.putConstraint(SpringLayout.SOUTH, btnDemander, -5, SpringLayout.SOUTH, pnlListeIndices);
        sl_pnlListeIndices.putConstraint(SpringLayout.EAST, btnDemander, -5, SpringLayout.EAST, pnlListeIndices);
        pnlListeIndices.setLayout(sl_pnlListeIndices);
        JTabbedPane tabbedPane_1 = new JTabbedPane(JTabbedPane.TOP);
        sl_pnlListeIndices.putConstraint(SpringLayout.NORTH, btnDemander, 5, SpringLayout.SOUTH, tabbedPane_1);
        sl_pnlListeIndices.putConstraint(SpringLayout.SOUTH, tabbedPane_1, -40, SpringLayout.SOUTH, pnlListeIndices);
        sl_pnlListeIndices.putConstraint(SpringLayout.NORTH, tabbedPane_1, 0, SpringLayout.NORTH, pnlListeIndices);
        sl_pnlListeIndices.putConstraint(SpringLayout.WEST, tabbedPane_1, 0, SpringLayout.WEST, pnlListeIndices);
        sl_pnlListeIndices.putConstraint(SpringLayout.EAST, tabbedPane_1, 0, SpringLayout.EAST, pnlListeIndices);
        pnlListeIndices.add(tabbedPane_1);
      
        
        tableau_indices = new JTable(mli);
		
	    listeIndice.addObserver(mli); 
	
		mli.update(listeIndice, null);
        JPanel ongIndices  = new JPanel();
        SpringLayout sl_ongIndices = new SpringLayout();
        ongIndices.setLayout(sl_ongIndices);
        
        JScrollPane sclpnIndices = new JScrollPane(tableau_indices);
        ongIndices.add(sclpnIndices);
        
       
        tabbedPane_1.addTab("Indices", null, ongIndices, null);
        sl_ongIndices.putConstraint(SpringLayout.NORTH, sclpnIndices, 0, SpringLayout.NORTH, ongIndices);
        sl_ongIndices.putConstraint(SpringLayout.WEST, sclpnIndices, 0, SpringLayout.WEST, ongIndices);
        sl_ongIndices.putConstraint(SpringLayout.SOUTH, sclpnIndices, -24, SpringLayout.SOUTH, ongIndices);
        sl_ongIndices.putConstraint(SpringLayout.EAST, sclpnIndices, 0, SpringLayout.EAST, ongIndices);
        
        JButton btnVoir_2 = new JButton("Voir");
        sl_ongIndices.putConstraint(SpringLayout.WEST, btnVoir_2, 0, SpringLayout.WEST, ongIndices);
        sl_ongIndices.putConstraint(SpringLayout.SOUTH, btnVoir_2, 0, SpringLayout.SOUTH, ongIndices);
        ongIndices.add(btnVoir_2);
        
        btnVoir_2.addActionListener(new ActionListener() {
	        public void actionPerformed(ActionEvent arg0) {
	        	
	        	
					Indice ind1 = mli.getListIndice().get(tableau_indices.getSelectedRow());
					FenetreVoirIndice fi = null;
					try {
						fi = new FenetreVoirIndice(mli,ind1);
					} catch (SQLException e) {
						e.printStackTrace();
					}
					
					fi.setVisible(true);
				
	        	
	        	
			
       
        /*-----------------------*/
      
        
        
        
	}
        });
	}
protected int getIdIndice() {		
		int result =0 ;
		
			int ligneSelectionner[] = tableau_indices.getSelectedRows();
			List<Integer> idModif = new ArrayList<Integer>();
				if(ligneSelectionner.length == 0)
				{
					JOptionPane.showMessageDialog(null,"Veuillez s\u00E9lectionner un indice");
					result = -1 ;
				}
				else if (ligneSelectionner.length >1)
				{
					JOptionPane.showMessageDialog(null,"Vous ne pouvez pas s\u00E9lectionner plus d'un indice");
					result = -1;
				}
				
				else 
				{
					//Enregistre tous les id des utilisateurs a supprimer dans une liste
					for(int i=0; i<ligneSelectionner.length;i++)
					{
						idModif.add(mli.getListIndice().get(ligneSelectionner[i]).getIdIndice());
					}
					//Supprime tous les utilisateur de la liste avec leur id
					for(int i=0; i<idModif.size();i++)
					{
						result = idModif.get(i);
					
						
					
					}	
					
				}
				
				return result;
		}
}
